﻿<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"         
        xmlns:res="clr-namespace:TTech.IP_Switcher.Features.IpSwitcher.LocationDetail.Resources"
        xmlns:ipc="clr-namespace:TTech.IP_Switcher.Features.IpSwitcher.IpAddress"
        xmlns:local="clr-namespace:TTech.IP_Switcher.Features.IpSwitcher.LocationDetail"
        xmlns:converters="clr-namespace:TTech.IP_Switcher.Converters"
        mc:Ignorable="d" 
        x:Class="TTech.IP_Switcher.Features.IpSwitcher.LocationDetail.LocationDetailView"
        WindowStartupLocation="CenterOwner" 
        ShowInTaskbar="False" 
        ResizeMode="NoResize" 
        WindowStyle="None"
        Loaded="Window_Loaded" 
        Style="{DynamicResource WindowStyle}"
        SizeToContent="WidthAndHeight"  >
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../../../Styles/Style.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <converters:InverseBooleanConverter x:Key="InverseBooleanConverter" />
        </ResourceDictionary>
    </Window.Resources>
    <Grid Background="{StaticResource BackgroundNormal}">
        <Grid.RowDefinitions>
            <RowDefinition Height="10" />
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="120"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="10" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="10" />
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="5"/>
            <ColumnDefinition Width="270"/>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="10" />
        </Grid.ColumnDefinitions>

        <TextBlock Name="DescriptionLabel" Text="{x:Static res:LocationDetailViewLoc.Name}" Grid.Row="1" Grid.Column="1" TextWrapping="Wrap" />
        <TextBox Name="DescriptionTextBox" Text="{Binding Description}" Grid.Row="1" Grid.Column="3" TextWrapping="Wrap" Margin="0,0,0,5" />

        <CheckBox IsChecked="{Binding DHCPEnabled}" Content="{x:Static res:LocationDetailViewLoc.UseDhcp}" Grid.Row="2" Grid.Column="3"  Margin="0,0,0,5"/>

        <TextBlock HorizontalAlignment="Left" Text="{x:Static res:LocationDetailViewLoc.IpAddresses}" Grid.Row="3" Grid.Column="1" />
        <Grid Grid.Row="3" Grid.Column="3" Margin="0,0,0,5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="1*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="1*"/>
            </Grid.RowDefinitions>
            <Rectangle Stroke="{StaticResource BorderBrushNormal}" StrokeThickness="1" Grid.ColumnSpan="2" Grid.RowSpan="2"/>
            <Rectangle Fill="{DynamicResource BackgroundHighlighted}" Grid.ColumnSpan="2" />
            <TextBlock Text="{x:Static res:LocationDetailViewLoc.Ip}" Margin="10,0" Grid.Row="0" Grid.Column="0"/>
            <TextBlock Text="{x:Static res:LocationDetailViewLoc.Netmask}" Margin="5,0" Grid.Row="0" Grid.Column="2"/>
            <ListBox x:Name="lvIp"  
                     BorderBrush="Transparent" 
                     ItemsSource="{Binding IPList}" 
                     Grid.Row="1" Grid.ColumnSpan="2" 
                     SelectionMode="Single" 
                     IsEnabled="{Binding DHCPEnabled, Converter={StaticResource InverseBooleanConverter}}"
                     Style="{DynamicResource ListBox}" 
                     Margin="0,3" >
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItem}" >
                        <EventSetter Event="PreviewGotKeyboardFocus" Handler="SelectCurrentItem"/>
                    </Style>
                </ListBox.ItemContainerStyle>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="1">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="1*"/>
                                <ColumnDefinition Width="1*"/>
                            </Grid.ColumnDefinitions>
                            <ipc:IpAddressView Grid.Column="0" Value="{Binding Path=IP, Mode=TwoWay}" />
                            <ipc:IpAddressView Grid.Column="1" Value="{Binding Path=NetMask, Mode=TwoWay}" />
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
        <StackPanel Grid.Row="3" Grid.Column="4" VerticalAlignment="Bottom" Margin="5,0,0,5">
            <Button Content="{x:Static res:LocationDetailViewLoc.Remove}" IsEnabled="{Binding ElementName=lvIp, Path=SelectedItems.Count}" Click="RemoveIp_Click" Margin="0,0,0,5"/>
            <Button Content="{x:Static res:LocationDetailViewLoc.Add}" IsEnabled="{Binding DHCPEnabled, Converter={StaticResource InverseBooleanConverter}}" Click="AddIp_Click" />
        </StackPanel>

        <TextBlock Text="{x:Static res:LocationDetailViewLoc.Gateways}" Grid.Row="4" Grid.Column="1" />
        <ListBox x:Name="lvGateway"  
                 ItemsSource="{Binding Gateways}" 
                 Grid.Row="4" Grid.Column="3" 
                 SelectionMode="Single" 
                 IsEnabled="{Binding DHCPEnabled, Converter={StaticResource InverseBooleanConverter}}"
                 Style="{DynamicResource ListBox}" 
                 Margin="0,0,0,5">
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItem}" >
                    <EventSetter Event="PreviewGotKeyboardFocus" Handler="SelectCurrentItem"/>
                </Style>
            </ListBox.ItemContainerStyle>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <ipc:IpAddressView Value="{Binding Path=IP, Mode=TwoWay}" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <StackPanel Grid.Row="4" Grid.Column="4" VerticalAlignment="Bottom" Margin="5,0,0,5">
            <Button Content="{x:Static res:LocationDetailViewLoc.Remove}" IsEnabled="{Binding ElementName=lvGateway, Path=SelectedItems.Count}" Click="RemoveGateway_Click" Margin="0,0,0,5" />
            <Button Content="{x:Static res:LocationDetailViewLoc.Add}" IsEnabled="{Binding DHCPEnabled, Converter={StaticResource InverseBooleanConverter}}" VerticalAlignment="Bottom" Click="AddGateway_Click" />
        </StackPanel>

        <TextBlock HorizontalAlignment="Left" Text="{x:Static res:LocationDetailViewLoc.DnsServers}" Grid.Row="5" Grid.Column="1" />
        <ListBox x:Name="lvDns"  
                 ItemsSource="{Binding DNS}" 
                 SelectionMode="Single" 
                 Grid.Column="3" Grid.Row="5"
                 IsEnabled="{Binding DHCPEnabled, Converter={StaticResource InverseBooleanConverter}}"
                 Style="{DynamicResource ListBox}" 
                 Margin="0,0,0,5" >
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItem}" >
                    <EventSetter Event="PreviewGotKeyboardFocus" Handler="SelectCurrentItem"/>
                </Style>
            </ListBox.ItemContainerStyle>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <ipc:IpAddressView Value="{Binding Path=IP, Mode=TwoWay}" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <StackPanel Grid.Row="5" Grid.Column="4" VerticalAlignment="Bottom" Margin="5,0,0,5" >
            <Button Content="{x:Static res:LocationDetailViewLoc.Remove}" IsEnabled="{Binding ElementName=lvDns, Path=SelectedItems.Count}" Click="RemoveDns_Click" Margin="0,0,0,5"/>
            <Button Content="{x:Static res:LocationDetailViewLoc.Add}" IsEnabled="{Binding DHCPEnabled, Converter={StaticResource InverseBooleanConverter}}" Click="AddDns_Click" />
        </StackPanel>

        <StackPanel Grid.Row="6" Grid.Column="3" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,5,0,0">
            <Button x:Name="btnSave"  Content="{x:Static res:LocationDetailViewLoc.Save}" IsDefault="True" Width="75" Click="SaveButton_Click" Margin="0,0,5,0"/>
            <Button x:Name="btnAbort"  Content="{x:Static res:LocationDetailViewLoc.Cancel}" IsCancel="True" Width="75" Click="CancelButton_Click"/>
        </StackPanel>
    </Grid>
</Window>
